using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
//ok

namespace WCFDicing.DataContracts
{
    /// <summary>
    /// klasa opisujaca krzeslo na ktorym siedzi gracz
    /// </summary>
    [System.Runtime.Serialization.DataContractAttribute( Namespace = "http://WCFDicing.DataContracts/2008/01", Name = "DicingChair" )]
    public class DicingChair
    {
        #region Fields + Get

        /// <summary>
        /// id krzesla
        /// </summary>
        private int chairId;

        /// <summary>
        /// get i set id krzesla
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "ChairId", Order = 0 )]
        public int ChairId
        {
            get { return chairId; }
            set { chairId = value; }
        }

        //czy na krzesle siedzi wlasciciel
        private bool isOwner;

        /// <summary>
        /// get i set  czy jest wlascicielem pokoju
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "IsOwner", Order = 1 )]
        public bool IsOwner
        {
            get { return isOwner; }
            set { isOwner = value; }
        }

        //czy miejsce jest zajete
        private bool isPlaying;

        /// <summary>
        /// get i set  czy miejsce jest zajete
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "IsPlaying", Order = 2 )]
        public bool IsPlaying
        {
            get { return isPlaying; }
            set { isPlaying = value; }
        }

        //id gracza ktory gra na krzesle
        private int playerId;

        /// <summary>
        /// get i set id gracza
        /// </summary>
        [System.Runtime.Serialization.DataMemberAttribute( IsRequired = false, Name = "PlayerId", Order = 3 )]
        public int PlayerId
        {
            get { return playerId; }
            set { playerId = value; }
        }

        #endregion

        #region Constructors
        /// <summary>
        /// konstruktor domyslny
        /// </summary>
        public DicingChair() { }

        /// <summary>
        /// konstruktor z zadanym indentyfikatorem
        /// </summary>
        /// <param name="chairId">id ktore bedzie mialo krzeslo</param>
        public DicingChair( int chairId )
        {
            this.chairId = chairId;
            this.isPlaying = false;
            this.isOwner = false;
        }
        #endregion

        #region Functions

        /// <summary>
        /// ustawia dane krzeslo jako wlasciciela
        /// </summary>
        public void makeThisOwner()
        {
            isOwner = true;
        }

        /// <summary>
        /// obluguje zajecie krzesla przez gracza
        /// </summary>
        /// <param name="playerId">id gracza</param>
        public void SitDown( int playerId )
        {
            isPlaying = true;
            this.playerId = playerId;
        }

        /// <summary>
        /// obsluguje wstanie gracza z krzesla
        /// </summary>
        /// <returns>zwraca czy gracz byl wlascicielem pokoju</returns>
        public bool StandUp()
        {
            isPlaying = false;
            this.playerId = 0;
            bool result = true;

            if ( isOwner )
            {
                isOwner = false;
                result = true;
            }
            else
                result = false;

            return result;
        }
        
        #endregion
    }
}
